class Account::AddressesController < Account::BaseController

  def index
    @addresses = @account.addresses
  end

  def edit
    @address = find_address
  end

  def update
    @address = find_address

    @address.update_attributes(params[:address])

    if @address.save
      flash[:notice] = 'Adres is aangepast.'

      redirect_to account_addresses_path
    else
      render :action => 'edit'
    end
  end

  def new
    @address = @account.addresses.new
  end

  def create
    @address = @account.addresses.new(params[:address])

    if @address.save
      flash[:notice] = 'Adres is aangemaakt.'

      redirect_to account_addresses_path
    else
      render :action => 'new'
    end
  end

  def destroy
    @address = find_address
    @address.destroy
  end

  private
    def find_address
      @account.addresses.find(params[:id])
    end

end